public class MyQueue {

    public class Node{
        public int val;
        public Node next;
        public Node prev;

        public Node(int val) {
            this.val = val;
        }
    }

    public Node front = null;
    public Node rear = null;

    public void offer(int x){
        Node node = new Node(x);
        if(isEmpty()){
            front = rear = node;
        }else {
            node.next = rear;
            rear.prev = node;
            rear = node;
        }
    }

    public int poll(){
        if(isEmpty()){
            throw new QueueNullExpation();
        }
        int tmp = front.val;

        front = front.prev;
        if(front != null){
            front.next = null;
        }

        return tmp;
    }

    public int peek(){
        if(isEmpty()){
            throw new QueueNullExpation();
        }
        return front.val;
    }

    public boolean isEmpty(){
        return front == null;
    }

}
